package com.fbs.wowo.manage.web;

import com.fbs.wowo.base.BaseController;
import com.fbs.wowo.base.Response;
import com.fbs.wowo.manage.service.AccountService;
import com.fbs.wowo.manage.service.VerifyCodeService;
import com.fbs.wowo.manage.vo.NamePassVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
public class AccountController extends BaseController {

    /**
     * 校验支付密码
     * @param vo userId password
     */
    @PostMapping("/pass")
    public Response verifyPass(@ModelAttribute NamePassVo vo) {
        accountService.verifyPass(vo);
        return success();
    }

    /**
     * 用户是否设置过支付密码
     * @param   userId 用户id
     * @return  1 设置过 0 未设置过
     */
    @GetMapping("/hasInitPass")
    public Response hasSetPass(@RequestParam String userId) {
        return success(accountService.hasSetPass(userId));
    }

    /**
     * 获取验证码
     */
    @PostMapping("/tel")
    public Response verifyCode(@RequestParam String tel) {
        verifyCodeService.sendVerifyCode(tel);
        return success();
    }

    /**
     * 修改密码
     */
    @PostMapping("/modify")
    public Response modify(@ModelAttribute NamePassVo vo) {
        accountService.modifyPayPassword(vo);
        return success();
    }

    /**
     * 忘记密码
     */
    @PostMapping("/forget")
    public Response forget(@ModelAttribute NamePassVo vo) {
        accountService.forgetPayPassword(vo);
        return success();
    }

    /**
     * 查看账户信息
     */
    @GetMapping("/account")
    public Response accountDetail(@RequestParam String userId) {
        return success(accountService.wallet(userId));
    }

    @Autowired
    private AccountService accountService;
    @Autowired
    private VerifyCodeService verifyCodeService;
}
